package com.ksyun.campus.client;

import com.ksyun.campus.client.domain.ClusterInfo;
import com.ksyun.campus.client.domain.StatInfo;
import com.ksyun.campus.client.service.ClientToMetaService;

import java.util.List;

public class EFileSystem extends FileSystem{
//---------------------修改部分-----------------------------------

    public ClientToMetaService clientToMetaService=new ClientToMetaService();

//---------------------修改部分-----------------------------------

    public EFileSystem() {
        this("default");
    }

    public EFileSystem(String fileSystemName) {
        this.defaultFileSystemName = fileSystemName;
    }

    public FSInputStream open(String path){
        path=this.ModifyPath(path);
        FSInputStream openStream = clientToMetaService.open(defaultFileSystemName, path);
        return openStream;
    }
    public FSOutputStream create(String path){
        path=this.ModifyPath(path);
        FSOutputStream createStream=clientToMetaService.create(defaultFileSystemName,path);
        return createStream;
    }
    public boolean mkdir(String path){
        path=this.ModifyPath(path);
        Boolean success=clientToMetaService.mkdir(defaultFileSystemName,path);
        return success;
    }
    public boolean delete(String path){
        path=this.ModifyPath(path);
        Boolean success=clientToMetaService.delete(defaultFileSystemName,path);
        return success;
    }
    public StatInfo getFileStats(String path){
        path=this.ModifyPath(path);
        StatInfo statInfo=clientToMetaService.getFileStats(defaultFileSystemName,path);
        return statInfo;
    }
    public List<StatInfo> listFileStats(String path){
        path=this.ModifyPath(path);
        List<StatInfo> statInfoList=clientToMetaService.listFileStats(defaultFileSystemName,path);
        return statInfoList;
    }
    public ClusterInfo getClusterInfo(){
        ClusterInfo clusterInfo = clientToMetaService.getClusterInfo();
        return clusterInfo;
    }

    /**
     * 防止传入的path没有带"/"
     * @param path
     * @return
     */
    public String ModifyPath(String path){
        if (!path.startsWith("/")) {
            path = new StringBuilder("/").append(path).toString();
        }
        return path;
    }

}
